<?php
/**
 * @Name: Node.php
 * @Author: yashuai<1762910894@qq.com>
 */

namespace app\backstage\controller\rbac;

use app\common\requests\StatusRequest;
use think\Request;
use app\common\services\rbac\NodeServices;
use HugCode\PhpUnits\Frame\Code\ConstCode;
use app\common\requests\rbac\NodeIDRequest;
use app\backstage\controller\BaseController;
use app\common\requests\rbac\NodeSaveRequest;

class Node extends BaseController
{

    public function __construct(NodeServices $service)
    {
        $this->service = $service;
    }

    /**
     * @Desc 列表
     * @param Request $request
     * @return \think\response\Json
     * @author yashuai<1762910894@qq.com>
     */
    public function index(Request $request)
    {
        $params = $request->all();
        $result = $this->service->getNotPageList($params);
        return _success($result);
    }

    /**
     * @Desc 添加
     * @param NodeSaveRequest $request
     * @return \think\response\Json
     * @author yashuai<1762910894@qq.com>
     */
    public function create(NodeSaveRequest $request)
    {
        $params = $request->getValidationData();
        $this->service->createRow($params);
        return _success();
    }

    /**
     * @Desc 编辑
     * @param NodeSaveRequest $request
     * @return \think\response\Json
     * @author yashuai<1762910894@qq.com>
     */
    public function update(NodeSaveRequest $request)
    {
        $validator = [
            'NodeID' => 'require|integer'
        ];
        $params    = $request->getValidationData($validator);
        $this->service->updateRow($params);
        return _success();
    }

    /**
     * @Desc 删除
     * @param NodeIDRequest $request
     * @return \think\response\Json
     * @author yashuai<1762910894@qq.com>
     */
    public function status(StatusRequest $request)
    {
        $params = $request->getValidationData();
        $this->service->updateStatus($params['ID'], $params['Status'], 'NodeStatus');
        return _success();
    }

}
